package cn.fhkj.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableConfigurationProperties({ProjectProperties.class})
public class SpringWebMvcConfigurer extends WebMvcConfigurerAdapter {
  @Autowired private ProjectProperties projectProperties;

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    super.addResourceHandlers(registry);
    String resourceHandler = projectProperties.getUrlpath();
    String ueditorHandler = projectProperties.getUeditorUrlpath();
    String resourceLocation = projectProperties.getUploadpath();

    //		"/attached/**"
    registry
        .addResourceHandler(resourceHandler + "**")
        //		"file:d:\\attached\\"
        .addResourceLocations("file:" + resourceLocation);

    registry
        .addResourceHandler(ueditorHandler + "**")
        .addResourceLocations("file:" + resourceLocation);
  }
}
